package com.ita.servlet.menu;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ita.factory.MServiceFactory;
import com.ita.pojo.Menu;
import com.ita.pojo.MenuType;
import com.ita.pojo.Merchant;
import com.ita.service.MenuService;
import com.ita.util.Constant;
import com.ita.util.JsonUtil;
import com.ita.util.TokenUtil;
import com.ita.vo.JsonResult;

/**
 * Servlet implementation class MenuServlet
 */
@WebServlet("/sec/menu/type")
public class TypeServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private MenuService fService;

	public TypeServlet() {
		super();
		fService = MServiceFactory.getMenuService();
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Access-Control-Allow-Origin", "*");
		
		List<MenuType> foodTypes = fService.loadMenuType();
	
		JsonResult jsonResult = new JsonResult();
		jsonResult.setCode(Constant.SUCEESS_CODE);
		jsonResult.setMsg(Constant.SUCCESS_MESSAGE);
		jsonResult.setData(foodTypes);

		String json = JsonUtil.getJsonFromObject(jsonResult);

		PrintWriter out = response.getWriter();
		out.write(json);
		out.flush();
		out.close();
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
